#include<stdio.h>
int c[1005];
int m,n,ans=1e8;
void dfs(int start,int money)
{
	int i;
	if(start==n)
	{
		ans = ans<money? ans:money;
		return;
	}
	else if(start>n)
		return;
	for(i=m;i>=1;i--)
	{
		if(start+i>n)
			i=n-start;
		dfs( start+i , money+c[start+i] ); 
	}
	return;
}
int main()
{
	scanf("%d%d",&n,&m);getchar();
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&c[i]);
	dfs(0,0);
	printf("%d\n",ans);
	return 0;
}
